<template>
  <!-- 未登录头部 -->
  <div class="h-container">
    <div class="h-content">
      <nuxt-link class="h-logo" to="/">
        <img src="../assets/images/h-logo.png" />
      </nuxt-link>
      <div class="h-nav">
        <div class="h-nav-list">
          <!-- <nuxt-link to="/" class="list-item" :class="number === 0 ? 'h-nav-line-active' : ''">首页</nuxt-link> -->
          <nuxt-link to="/" class="list-item">首页</nuxt-link>
          <nuxt-link class="list-item" to="/myAddFans">我要涨粉</nuxt-link>
          <!-- <div class="list-item" :class="number === 1 ? 'h-nav-line-active' : ''" @click="jump(1)">我要涨粉</div> -->
          <div class="list-item" :class="number === 2 ? 'h-nav-line-active' : ''" @click="jump(2)">多账号管理</div>
          <!-- <div class="list-item" :class="number === 3 ? 'h-nav-line-active' : ''" @click="jump(3)">我要卖货</div> -->
          <nuxt-link class="list-item" to="/pickGoodsHall" >我要卖货</nuxt-link>
        </div>
        <div class="h-login" v-if="!token">
          <img src="../assets/images/h-user.png"/>
          <nuxt-link to="/login" class="h-login-txt">注册/登录</nuxt-link>
        </div>
        <div class="h-login" v-else>
          <p class="welcome"><span class="color-blue">欢迎你</span>,{{name}} </p>
          <p class="logout-interpage" @click="logout">退出</p>
          <div class="login-interpage" @click="login">进入</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  // props: {
  //   number: {
  //     type: Number,
  //     default: 0
  //   }
  // },
  components: {
  },
  data() {
    return {
      // number: 0
      token:"",
      name:"",
      userid:"",
    }
  },
  computed: { //计算属性
    number() {
      return this.$store.state.index;
    },
  },
  mounted(){
    this.token = localStorage.getItem('token');
    this.name = localStorage.getItem('name');
    this.userid = localStorage.getItem('userid');
  },
  methods: {
    // showLine(number) { // 显示动态
    //   let obj = {}
    //   if (number === 0) {
    //     obj.left = 0
    //   } else if (number === 1) {
    //     obj.left = '160px'
    //   } else if(number === 2) {
    //     obj.left = '324px'
    //   }else if(number === 3){
    //     obj.left = '648px'
    //   }
    //   return obj
    // },
    jump(index){
      //未来还得做个判断，判断是否是登录
      this.$store.commit('setIndex',index);
      if (index === 1) {
        this.$router.push('/myAddFans')
      }else if (index === 3) {
        this.$router.push('/pickGoodsHall')
      } 
      if(!this.$isNull(this.userid)) { //用户信息不为空，我们才保存历史记录
        // if (index === 1) { //我要涨粉保存路由跳转的状态
        //   this.go('/myAddFans');
        // }else 
        if (index === 2) { //多账号管理保存路由跳转的状态
          this.$router.replace('/multiPlat/accountPreview');
        } 
        // else {
        //   this.$router.replace('/myAddFans');
        // }
      } else {
        this.$router.replace('/login'); //没有这个状态直接去登录
      }
    },
    logout(){ //退出
  
      this.$logout() //清除token和用户信息
      this.$store.commit('user/setUser', { 
        userid: '',
        token: '',   
        name: '',   
        auth: false, //区分是否登录  true登录
      })
      localStorage.removeItem('list');
      localStorage.removeItem('ksAccount');
      window.location.href ="/"
    },
    login(){ //进入
      // if (this.$store.state.index === 1) { //我要涨粉保存路由跳转的状态
      //   this.go('/myAddFans');
      // }else if (this.$store.state.index === 2) {//多账号管理
      //   this.$router.replace('/multiPlat/accountPreview');
      // }else if (this.$store.state.index === 3) {
      //   this.$router.push('/pickGoodsHall')
      // } 
      this.$router.push('/pickGoodsHall')
      // if (this.$store.state.index === 1) { //我要涨粉保存路由跳转的状态
      //   this.go('/myAddFans');
      // }else if (this.$store.state.index === 2) {//多账号管理
      //   this.$router.replace('/multiPlat/accountPreview');
      // }
    },
    // 我要涨粉和多账号管理以及我要卖货可以跳到登录后的页面
  }
}
</script>

<style scoped>
  a{
    padding:0;
  }
  .h-container {
    width:100%;
    height: 80px;
    min-width: 1200px;
    background: #fff;
    box-shadow: 1px 2px 2px #f5f5f4;
    position: sticky;
    top: 0;
    left:0;
    z-index: 99;
  }
  .h-content {
    width: 1200px;
    margin: 0 auto;
    display: flex;
    height: 80px;
    align-items: center;
    justify-content: space-between;
  }
  .h-logo {
    width: 175px;
    height: 36px;
  }
  .h-logo img {
    width: 100%;
    height: 100%;
  }
  .h-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .h-nav-list {
    display: flex;
    width: 397px;
    justify-content: space-between;
    border-right: 1px solid #e1e1e1;
    padding-right: 43px;
    position: relative;
  }
  .h-nav-list .list-item {
    text-align: center;
    font-size: 18px;
    color: #333;
    cursor: pointer;
    width: 80px;
    white-space: nowrap;
    user-select:none;
  }
  .list-item:hover{
    color:#0096e6;
  }
  .h-nav-line {
    width: 80px;
    height: 3px;
    background: #0096e6;
    position: absolute;
    bottom: -30px;
    /* left: 0; */
    transition: all ease-out .3s;
  }
  .h-nav-line-active {
    color: #0096e6 !important;
  }
  .h-login {
    display: flex;
    align-items: center;
    margin-left: 43px;
    cursor: pointer;
  }
  .h-login-txt {
    color: #0096e6;
    font-size: 18px;
    flex: 1;
    margin-left: 6px;
  }
  .login-interpage{
    border-radius: 4px;
    padding: 7px 14px 8px;
    font-size: 14px;
    color: #ffffff;
    text-align: center;
    cursor: pointer;
    background:#0096e6;
    margin-left:10px;
  }
  .login-interpage:hover{
    background:#66B1FF;
  }
  .welcome{
    display: inline-block;
    text-align: right;
    margin: 0 12px;
    line-height: 36px;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .logout-interpage{
    color:#0096e6;
  }
  .color-blue{
    color:#0096e6;
  }
</style>
